home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / timedat.exe / DEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-05-09  |  10KB  |  313 lines

  1.  
  2. /*
  3.  Copyright 1992 - John K. Humkey
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <string.h>
  10. #include <dos.h>
  11. #include "timespan.h"
  12. #include "timpoint.h"
  13.  
  14. void astro_to_date(int *year, int *month, int *day, long *ast);
  15. void date_to_astro(int *year, int *month, int *day, long *ast);
  16. void time_to_astro(int *hour, int *mins,  int *sec, int *millisec, long *ast);
  17. void astro_to_time(int *hour, int *mins,  int *sec, int *millisec, long *ast);
  18.  
  19. void span_demo();
  20. void point_demo();
  21.  
  22. int __european;
  23.  
  24. main()
  25. {
  26.   __european = 0;
  27.     span_demo();
  28.     point_demo();
  29. }
  30.  
  31. void span_demo()
  32. {
  33.           timespan comboone(100L,0,29,29);
  34.           timespan combotwo(100L,0,29,29);
  35.           timespan combothree(200L,0,0,0);
  36.           timespan combofour(100L,0,29,30);
  37.           timespan combototal;
  38.  
  39.           clrscr();
  40.           printf("\nTime Span Demo\n\n");
  41.  
  42.           printf("ts = ts + ts\n");
  43.           combototal = comboone + combotwo;
  44.           comboone.print();
  45.           combotwo.print();
  46.           combototal.print();
  47.           printf("\n"); getch();
  48.  
  49.           printf("ts = ta - tb    (a<b type 1)\n");
  50.           combototal = comboone - combothree;
  51.           comboone.print();
  52.           combothree.print();
  53.           combototal.print();
  54.           printf("\n"); getch();
  55.  
  56.           printf("ts = ta - tb    (a<b type 2)\n");
  57.           combototal = comboone - combofour;
  58.           comboone.print();
  59.           combofour.print();
  60.           combototal.print();
  61.           printf("\n"); getch();
  62.  
  63.           printf("ts = ta - tb    (a==b)\n");
  64.           combototal = comboone - combotwo;
  65.           comboone.print();
  66.           combotwo.print();
  67.           combototal.print();
  68.           printf("\n"); getch();
  69.  
  70.           printf("ts = ta - tb    (a>b type 1)\n");
  71.           combototal = combothree - comboone;
  72.           combothree.print();
  73.           comboone.print();
  74.           combototal.print();
  75.           printf("\n"); getch();
  76.  
  77.           printf("ts = ta - tb    (a>b type 2)\n");
  78.           combototal = combofour - comboone;
  79.           combofour.print();
  80.           comboone.print();
  81.           combototal.print();
  82.           printf("\n"); getch();
  83.  
  84.           printf("ts = ts * 2\n");
  85.           combototal = combothree * 2;
  86.           combothree.print();
  87.           combototal.print();
  88.           printf("\n"); getch();
  89.  
  90.           printf("ts = ts / 2\n");
  91.           combototal = combothree / 2;
  92.           combothree.print();
  93.           combototal.print();
  94.           printf("\n"); getch();
  95.  
  96.           printf("ta < tb\n");
  97.           printf("should be 1 is %d\n",comboone   < combothree);
  98.           printf("should be 1 is %d\n",comboone   < combofour);
  99.           printf("should be 0 is %d\n",comboone   < combotwo);
  100.           printf("should be 0 is %d\n",combothree < comboone);
  101.           printf("should be 0 is %d\n",combofour  < comboone);
  102.           printf("\n"); getch();
  103.  
  104.           printf("ta > tb\n");
  105.           printf("should be 0 is %d\n",comboone   > combothree);
  106.           printf("should be 0 is %d\n",comboone   > combofour);
  107.           printf("should be 0 is %d\n",comboone   > combotwo);
  108.           printf("should be 1 is %d\n",combothree > comboone);
  109.           printf("should be 1 is %d\n",combofour  > comboone);
  110.           printf("\n"); getch();
  111.  
  112.           printf("ta == tb\n");
  113.           printf("should be 0 is %d\n",comboone   == combothree);
  114.           printf("should be 0 is %d\n",comboone   == combofour);
  115.           printf("should be 1 is %d\n",comboone   == combotwo);
  116.           printf("should be 0 is %d\n",combothree == comboone);
  117.           printf("should be 0 is %d\n",combofour  == comboone);
  118.           printf("\n"); getch();
  119.  
  120.           printf("ta != tb\n");
  121.           printf("should be 1 is %d\n",comboone   != combothree);
  122.           printf("should be 1 is %d\n",comboone   != combofour);
  123.           printf("should be 0 is %d\n",comboone   != combotwo);
  124.           printf("should be 1 is %d\n",combothree != comboone);
  125.           printf("should be 1 is %d\n",combofour  != comboone);
  126.           printf("\n"); getch();
  127.  
  128.           printf("ta <= tb\n");
  129.           printf("should be 1 is %d\n",comboone   <= combothree);
  130.           printf("should be 1 is %d\n",comboone   <= combofour);
  131.           printf("should be 1 is %d\n",comboone   <= combotwo);
  132.           printf("should be 0 is %d\n",combothree <= comboone);
  133.           printf("should be 0 is %d\n",combofour  <= comboone);
  134.           printf("\n"); getch();
  135.  
  136.           printf("ta >= tb\n");
  137.           printf("should be 0 is %d\n",comboone   >= combothree);
  138.           printf("should be 0 is %d\n",comboone   >= combofour);
  139.           printf("should be 1 is %d\n",comboone   >= combotwo);
  140.           printf("should be 1 is %d\n",combothree >= comboone);
  141.           printf("should be 1 is %d\n",combofour  >= comboone);
  142.           printf("\n"); getch();
  143.  
  144.           printf("ts += ts\n");
  145.           combototal = comboone;
  146.           combototal.print();
  147.           combototal += combotwo;
  148.           combotwo.print();
  149.           combototal.print();
  150.           printf("\n"); getch();
  151.  
  152.           printf("ts -= ts\n");
  153.           combototal = combothree;
  154.           combototal.print();
  155.           combototal -= combotwo;
  156.           combotwo.print();
  157.           combototal.print();
  158.           printf("\n"); getch();
  159.  }
  160.  
  161. void point_demo()
  162. {
  163. char str[80];
  164.  
  165.           timepoint comboone(1962,9,2,2,29,29);
  166.           timespan  combotwo(0,0,30,30);
  167.           timepoint combothree(0,0,0,2,10,10);
  168.           timepoint combototal;
  169.  
  170.           clrscr();
  171.           printf("\nTime Point Demo\n\n");
  172.  
  173.           combototal = comboone + combotwo;
  174.           comboone.print();
  175.           combotwo.print();
  176.           combototal.print();
  177.  
  178.           printf("\nTime Point String Demo\n\n");
  179.           printf("American format\n");
  180.           printf("mdy2w %s\n",comboone.mdy2w(str));
  181.           printf("mdy4w %s\n",comboone.mdy4w(str));
  182.           printf("mdy2  %s\n",comboone.mdy2(str));
  183.           printf("mdy4  %s\n",comboone.mdy4(str));
  184.           printf("y2md  %s\n",comboone.y2md(str));
  185.           printf("y4md  %s\n",comboone.y4md(str));
  186.  
  187.           printf("\nEuropean format\n");
  188.           __european = 1;
  189.           printf("mdy2w %s\n",comboone.mdy2w(str));
  190.           printf("mdy4w %s\n",comboone.mdy4w(str));
  191.           printf("mdy2  %s\n",comboone.mdy2(str));
  192.           printf("mdy4  %s\n",comboone.mdy4(str));
  193.           printf("y2md  %s\n",comboone.y2md(str));
  194.           printf("y4md  %s\n",comboone.y4md(str));
  195.  
  196. getch();
  197. }
  198.  
  199. /*  #    #   ####    #####     #     ####   ######  */
  200. /*  ##   #  #    #     #       #    #    #  #       */
  201. /*  # #  #  #    #     #       #    #       #####   */
  202. /*  #  # #  #    #     #       #    #       #       */
  203. /*  #   ##  #    #     #       #    #    #  #       */
  204. /*  #    #   ####      #       #     ####   ######  */
  205. /*                                                  */
  206.  
  207. /* The following routines are used by the timepoint */
  208. /* and timespan classes, and will need to be placed */
  209. /* in your normal user libraries (or included in    */
  210. /* source form in your code.)                       */
  211.  
  212. /* The following routines...                        */
  213. /*                                                  */
  214. /*      astro_to_date                               */
  215. /*      date_to_astro                               */
  216. /*      astro_to_time                               */
  217. /*      time_to_astro                               */
  218. /*                                                  */
  219. /* were taken from an article in "68' Micro Journal"*/
  220. /* from Volume VIII Issue II * February 1986.       */
  221. /*                                                  */
  222. /* To the best of my knowledge the magazine is out  */
  223. /* of business, which is a shame because they pub-  */
  224. /* lished some interesting source code.             */
  225. /*                                                  */
  226. /* The article was under "C" User Notes and was by  */
  227. /* Edgar M. (Bud) Pass, Ph.D.                       */
  228. /* Mr. Pass adapted the routines from ...           */
  229. /* "Communications of the ACM * Oct 68 p657, Oct 70 */
  230. /* p621, Oct 72 p918.                               */
  231. /*                                                  */
  232. /* Several other routines are included in the       */
  233. /* original article (to calculate the day of the    */
  234. /* year, day of the week) but are not needed for the*/
  235. /* timepoint and timespan classes.                  */
  236. /*                                                  */
  237. /* I don't pretend to understand the underlying     */
  238. /* theory of how the routines work, I just know that*/
  239. /* used in combination with the timepoint and       */
  240. /* timespan classes they can accurately represent   */
  241. /* any point from about 4000 years ago to any point */
  242. /* in the future (with down to the millisecond      */
  243. /*